package com.table.util;

import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;

import org.reflections.Reflections;

import com.table.annotation.ExportableAnnotation;

public class ReflectionAnnotationLookup {

	public static Set<Class<? extends Object>> findAllEntitiesAnnotadedClasses(Class<? extends Annotation> annotationClass){
		
		Reflections reflections = new Reflections("com.table.entity");
		Set<Class<? extends Object>> classSet = reflections.getTypesAnnotatedWith(annotationClass);
		
		return classSet;
	
	}

	
	public static Set<String> getAllAnnotadedClassesName(Class<? extends Annotation> annotationClass){
		
		Set<String> classNameSet = new HashSet<String>();
		Set<Class<? extends Object>> classSet = findAllEntitiesAnnotadedClasses(annotationClass);
		
		for(Class<? extends Object> clazz : classSet) {
			
			Annotation annotation = clazz.getAnnotation(annotationClass);
		
			if(annotation instanceof ExportableAnnotation){
				classNameSet.add(((ExportableAnnotation) annotation).nome());
			}
		}
		return classNameSet;	
	}
	
}
